<?php include_stylesheets_for_form($form) ?>
<?php include_javascripts_for_form($form) ?>
<?php use_helper('LetsManager','Date') ?>


<form
  action="<?php echo url_for('@lets_exchangeByManager_'.($form->getObject()->isNew() ? 'create' : 'update?id='.$form->getObject()->getId())) ?>"
  method="post">
<?php if (!$form->getObject()->isNew()): ?>
  <input type="hidden" name="sf_method" value="put" /> 
<?php else: ?>
  Pour le débiteur et créditeur, saisir au moins 2 lettres du nom, prénom
  ou le numéro d'adhérent puis choisir le membre dans la liste.
<?php endif ?>
<table class="formtable" summary="Register a transaction">

  <!-- Form body, displays fields -->

  <tbody>
  <?php echo $form->renderGlobalErrors() ?>
    <?php if($form->isNew()): ?>
      <tr>
        <th><?php echo $form['creditor_id']->renderLabel() ?></th>
        <td><?php echo $form['creditor_id'].' '.$form['creditor_id']->renderError() ?></td>
      </tr>
      
      <tr>
        <?php if($can_select_debitor): ?>
          <th><?php echo $form['debitor_id']->renderLabel() ?></th>
          <td><?php echo $form['debitor_id'].' '.$form['debitor_id']->renderError() ?></td>
        <?php else: ?>
          <th>Débiteur </th>
          <td><?php echo $sf_user->getAssociationName() ?>
        <?php endif ?>
      </tr>
      <tr>
        <th><?php echo $form['date_exchange']->renderLabel() ?></th>
        <td><?php echo $form['date_exchange'].' '.$form['date_exchange']->renderError() ?></td>
      </tr>
      <!-- we don't display check box because association account doesn't validate -->
      <?php if($can_select_debitor): ?>
      <tr>
        <th><?php echo $form['state_validated']->renderLabel() ?></th>
        <td><?php echo $form['state_validated'].' '.$form['state_validated']->renderError() ?></td>
      </tr>
      <?php endif ?>
    <?php else: ?>
      <tr>
        <th>Créditeur</th>
        <td><?php echo lets_format_member($creditor_member,true)?></td>
      </tr>
      <tr>
        <th>Débiteur</th>
        <td><?php echo lets_format_member($debitor_member,true)?></td>
      </tr>
      <tr>
        <th>Date de l'échange</th>
        <td><?php echo format_date($date_exchange)?></td>
      </tr>
    <?php endif ?>
    <tr>
      <th><?php echo $form['name']->renderLabel() ?></th>
      <td><?php echo $form['name'] ?> <?php echo $form['name']->renderError() ?></td>
    </tr>
    <tr>
      <th><?php echo $form['category_id']->renderLabel() ?></th>
      <td><?php echo $form['category_id'] ?> <?php echo $form['category_id']->renderError() ?></td>
    </tr>
    <tr>
      <th><?php echo $form['amount']->renderLabel() ?></th>
      <td><?php echo $form['amount'].' '.$form['amount']->renderError().' '.lets_money_name() ?></td>
    </tr>

  </tbody>
  <tfoot>
    <tr>
      <td colspan="2">
      <?php echo $form->renderHiddenFields() ?> 
      <?php echo link_to('Annuler','@lets_exchange_list', array('class' => 'blue button')); ?>
      <input type="submit" value="Sauvegarder" class="blue button" />
      </td>
    </tr>
  </tfoot>
</table>
</form>
